from django.db import models
from django.db import connection


class ProjectDataFields:
    project_name = ' '
    project_id = -1
    
    def __init__(self, sql_row):
        self.project_name = sql_row[0]
        self.project_id = sql_row[1]
    
        
class ProjectDataManager(models.Manager):
    def get_query_set(self):
        return super(ProjectDataManager, self).get_query_set()
        
    def all(self):
        cursor = connection.cursor()
        cursor.execute("""
                        SELECT p.name_project, p.id
                        FROM timesheet_project p
                        """)
        result_list = []
        for row in cursor.fetchall():
            elem_t = ProjectDataFields(row)
            result_list.append(elem_t)
        return result_list

